﻿using Natural.Attributes;
using Natural.Model;
using Natural.Providers;

namespace Natural.Actions
{
    [Impl(Type = ImplType.Action, Name = "Inactivate", Strategy = "Default", ApplyTo = typeof(Activable), Version = 0, Priority = 0)]
    public class Inactivate<T> where T : class, Activable
    {
        public virtual void Execute(ActionContext context, int id)
        {
            T entity = Executor.First<T>(new ActionContext(context), new Expression("this.Id=@Id", new Parameters() { { "Id", id } }));
            entity.Status = Modeler.Status(typeof(T).Name, "Inactive");
            Executor.Execute<T>(new ActionContext(context), "Update", entity);
        }
    }
}
